﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jayden.Dll.Web.HtmlControls;

namespace Jayden.Site.PopjesInDeZak.Dll
{
	public class PopjesPagedDiv : Div
	{
		protected A m_Previous;
		protected A m_Next;
		protected Img m_PreviousImage;
		protected Img m_NextImage;

		public override void Load(System.Xml.XmlNode node, Jayden.Dll.Web.HtmlControlLoader loader)
		{
			base.Load(node, loader);

			m_Previous = GetElementByServerId<A>("previous", true);
			m_Next = GetElementByServerId<A>("next", true);
			m_PreviousImage = GetElementByServerId<Img>("previousImage", true);
			m_NextImage = GetElementByServerId<Img>("nextImage", true);

		}

		public override void ProcessJsRequest(Jayden.Dll.Web.HttpHandlerContext context)
		{
			base.ProcessJsRequest(context);

			context.Js["NavigationImages"].Append(@"
	jayden.sfn.preload([
		'/Images/arrow.left.on.png',
		'/Images/arrow.right.on.png'
	]);
");

			context.Js["PopjesPagedDiv"].AppendOnInit(@"
	var $previous = $('#" + m_Previous.Id + @"');
	var $next = $('#" + m_Next.Id + @"');
	var $previousImg = $('#" + m_PreviousImage.Id + @"');
	var $nextImg = $('#" + m_NextImage.Id + @"');

	$previousImg.mouseenter(function(){ $previousImg.data('old-src', $previousImg.attr('src')); $previousImg.attr('src', '/Images/arrow.left.on.png'); });
	$previousImg.mouseleave(function(){ $previousImg.attr('src', $previousImg.data('old-src')); });

	$nextImg.mouseenter(function(){ $nextImg.data('old-src', $nextImg.attr('src')); $nextImg.attr('src', '/Images/arrow.right.on.png'); });
	$nextImg.mouseleave(function(){ $nextImg.attr('src', $nextImg.data('old-src')); });
");
		}

	}
}